using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GraphCompiler.Core;
using GraphCompiler.Core.Exceptions;
using GraphCompiler.Core.SyntaxRepresentation;

namespace GraphCompiler.Core.Parsing
{
    public class BoxParser : ParserBase<BoxNode>
    {
        public override BoxNode ParseTypedNode(TokenCollection tokens)
        {
            _tokens = tokens;

            if (_tokens.IsEmpty)
                throw new SyntaxErrorException();

            ConsumeToken("box");
            Token name = ReadToken();
            ConsumeToken("{");
            ConsumeToken("}");

            return new BoxNode(name.String);
        }

        public override bool IsApplicable(TokenCollection tokens)
        {
            if (tokens.IsEmpty)
                return false;

            return tokens.First().Equals(new Token("box"));
        }
    }
}
